package com.joy.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.joy.service.UserService;
import com.joy.validator.LoginValidator;
import com.joy.validator.RegisterValidator;

public class IndexController extends Controller {

    UserService userService=new UserService();

    public void index() {
        renderJsp("index.jsp");
    }


    @Before(LoginValidator.class)
    public void login() {
        renderHtml("ok");
    }
    @Before(RegisterValidator.class)
    public void register() {
        String username = getPara("username");
        String password = getPara("password");
        boolean result = userService.addUser(username, password);
        if (result) {
            renderJson("注册成功！");
        }else{
            renderJson("注册失败");
        }
    }
}
